package kuanshu.controller;

import kuanshu.bean.ZuKeXinXi;
import kuanshu.mapper.ZuKeXinXiMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/zukexinxi")
public class ZuKeXinXiController {

    @Autowired
    private ZuKeXinXiMapper zuKeXinXiMapper;

    // 获取所有租客信息
    @GetMapping("/all")
    public List<ZuKeXinXi> getAllZuKeXinXi() {
        return zuKeXinXiMapper.getAllZuKeXinXi();
    }

    // 根据ID获取租客信息
    @GetMapping("/{id}")
    public ZuKeXinXi getZuKeXinXiById(@PathVariable int id) {
        return zuKeXinXiMapper.getZuKeXinXiById(id);
    }

    // 添加租客信息
    @PostMapping
    public String addZuKeXinXi(@RequestBody ZuKeXinXi zuKeXinXi) {
        zuKeXinXiMapper.addZuKeXinXi(zuKeXinXi);
        return "添加成功";
    }

    // 更新租客信息
    @PutMapping
    public String updateZuKeXinXi(@RequestBody ZuKeXinXi zuKeXinXi) {
        zuKeXinXiMapper.updateZuKeXinXi(zuKeXinXi);
        return "更新成功";
    }

    // 删除租客信息
    @DeleteMapping("/{id}")
    public String deleteZuKeXinXi(@PathVariable int id) {
        zuKeXinXiMapper.deleteZuKeXinXi(id);
        return "删除成功";
    }
}